package com.yuexunit.finance.common.util;

import java.io.FileOutputStream;
import java.util.List;

import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFCellStyle;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;

import com.yuexunit.finance.project.action.v1.model.output.Capital;

/**
*@version 创建时间：2016年10月13日 上午10:46:50
*@author NTBK-021-1006
*类说明
*/

public class CreateSimpleExcelToDisk {
	public static HSSFWorkbook createSimpleExcelToDisk(String sheetName, String[] rowName, List<Capital> dataList){
		// 第一步，创建一个webbook，对应一个Excel文件  
        HSSFWorkbook wb = new HSSFWorkbook(); 
        // 第二步，在webbook中添加一个sheet,对应Excel文件中的sheet  
        HSSFSheet sheet = wb.createSheet(sheetName); 
        // 第三步，在sheet中添加表头第0行,注意老版本poi对Excel的行数列数有限制short  
        HSSFRow row = sheet.createRow((int) 0);
        // 第四步，创建单元格，并设置值表头 设置表头居中  
        HSSFCellStyle style = wb.createCellStyle();  
        style.setAlignment(HSSFCellStyle.ALIGN_CENTER); // 创建一个居中格式  
        HSSFCell cell = row.createCell((short) 0);
        int k = 1;
        for (String r : rowName) {
        	cell.setCellValue(r);  
            cell.setCellStyle(style);
        	cell = row.createCell((short) k++);
		}
        
        for (int i = 0; i < dataList.size(); i++) {
        	row = sheet.createRow((int) i + 1);  
        	Capital c = dataList.get(i);
        	int j = 0;
        	row.createCell((short) j++).setCellValue(c.getEnterpriseName());
        	row.createCell((short) j++).setCellValue(c.getProductName());
        	row.createCell((short) j++).setCellValue(c.getFinanceNumber());
        	row.createCell((short) j++).setCellValue(c.getAuditDateTime());
        	row.createCell((short) j++).setCellValue(c.getMinDays() + "天~" + c.getMaxDays() + "天");
        	row.createCell((short) j++).setCellValue(c.getFinanceAmount().doubleValue());
        	row.createCell((short) j++).setCellValue(c.getTotalLoanAmount().doubleValue());
        	row.createCell((short) j++).setCellValue(c.getTotalWaitLoanAmount().doubleValue());
        	row.createCell((short) j++).setCellValue(c.getTotalReceivedAmount().add(c.getTotalWaitLoanAmount()).doubleValue());
        	row.createCell((short) j++).setCellValue(c.getTotalReceivedAmount().doubleValue());
        	row.createCell((short) j++).setCellValue(c.getTotalWaitReceivedAmount().doubleValue());
        	row.createCell((short) j++).setCellValue(c.getInterestAmount().doubleValue());
        	row.createCell((short) j++).setCellValue(c.getInterestReceiveAmount().doubleValue());
        	row.createCell((short) j++).setCellValue(c.getInterestWaitReceiveAmount().doubleValue());
        	row.createCell((short) j++).setCellValue(c.getReceivableBail().doubleValue());
        	row.createCell((short) j++).setCellValue(c.getReceivedBail().doubleValue());
        	row.createCell((short) j++).setCellValue(c.getReceivableAddBail().doubleValue());
        	row.createCell((short) j++).setCellValue(c.getReceivedAddBail().doubleValue());
        	row.createCell((short) j++).setCellValue(c.getReturnBail().doubleValue());
        	row.createCell((short) j++).setCellValue(c.getReceivableInsureAmount().doubleValue());
        	row.createCell((short) j++).setCellValue(c.getReceivedInsureAmount().doubleValue());
        	row.createCell((short) j++).setCellValue(c.getPaymentableInsureAmount().doubleValue());
        	row.createCell((short) j++).setCellValue(c.getPaidInsureAmount().doubleValue());
        	row.createCell((short) j++).setCellValue(c.getReceivableOtherAmount().doubleValue());
        	row.createCell((short) j++).setCellValue(c.getReceivedOtherAmount().doubleValue());
        	row.createCell((short) j++).setCellValue(c.getPaymentableOtherAmount().doubleValue());
        	row.createCell((short) j++).setCellValue(c.getPaidOtherAmount().doubleValue());
		}
        
        try  
        {  
//            FileOutputStream fout = new FileOutputStream("D:\\zjjr\\trunk\\指尖金融\\项目源码\\service\\web\\src\\main\\webapp\\html\\platform\\excelTemplate\\资金台账.xls");
            FileOutputStream fout = new FileOutputStream("C:\\Finance\\Tomcat\\Tomcat7.0\\webapps\\finance-web\\html\\platform\\excelTemplate\\资金台账.xls");
            wb.write(fout);  
            fout.close();  
        }  
        catch (Exception e)  
        {  
            e.printStackTrace();  
        }  
        
        return wb;
	}
}
